<?php

namespace Dcat\Admin\Caijiwebinfo\Forms\Field;

use Dcat\Admin\Form\Field;
use Dcat\Admin\Caijiwebinfo\Forms\GetWxgzhArt;
use Dcat\Admin\Widgets\Modal;
use Dcat\Admin\Support\Helper;
use Illuminate\Support\Arr;
use Dcat\Admin\Admin;

class Caijiwebinfo extends Field
{
    protected $view = 'ycookies.caijiwebinfo::index';

    protected $class = 'btn-primary';

    protected $btntxt = '采集web信息';

    protected $title_class = 'title';

    protected $content_class = 'content';

    protected $icon  = 'feather icon-crosshair';

    /**
     * Htmlable.
     *
     * @var string|\Closure
     */
    protected $html = '';

    /**
     * @var string
     */
    protected $label = '';

    /**
     * @var bool
     */
    protected $plain = false;


    public function __construct($label = '',$arguments = [])
    {
        if(!empty($label)){
            $this->btntxt = $label;
        }
        $this->label = Arr::get($arguments, 0);
    }


    public function icon(string $icon)
    {
        $this->icon = $icon;
        return $this;
    }

    public function titleClass($strings){
        $this->title_class = $strings;
        return $this;
    }

    public function contentClass($strings){
        $this->content_class = $strings;
        return $this;
    }

    /**
     * Render html field.
     *
     * @return string
     */
    public function render()
    {
        $payload = ['title_class'=>$this->title_class,'content_class'=> $this->content_class];
        $modal = Modal::make()
            ->lg()
            ->title($this->btntxt)
            ->body(GetWxgzhArt::make()->payload($payload))
            ->button('<button class="btn btn-default"><i class="'.$this->icon.'"></i>'.$this->btntxt.'</button>');

        $this->html = $modal;
        if ($this->html instanceof \Closure) {
            $this->html = Helper::render(
                $this->html->call($this->values(), $this->form)
            );
        }

        if ($this->plain) {
            return $this->html;
        }

        $viewClass = $this->getViewElementClasses();

        return <<<EOT
<div class="{$viewClass['form-group']}">
    <label  class="{$viewClass['label']} control-label">{$this->label}</label>
    <div class="{$viewClass['field']}">
        <div class="{$this->getElementClassString()}">{$this->html}</div>
    </div>
</div>
EOT;
    }

}
